@extends('Admin.layout.layout')
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>广告列表</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form action="" method="get">
                                {{csrf_field()}}
                                <div class="col-sm-12">
                                    <a class="btn btn-sm btn-primary fl mr10" href="{{url('/foradmin/advertisinglist/create')}}">新增</a>
                                    <button type="submit" class="btn btn-sm btn-primary fr">查询</button>
                                    <div class="input-group fr mr10">
                                        <select class="form-control " style="height: 30px; padding:0 12px;" name="position">
                                            <option value="">广告位置</option>
                                            @foreach($category as $k=>$v)
                                                <option @if($v['id'] == $search_params['position']) selected="selected" @endif value="{{$v['id']}}">{{$v['title']}}</option>
                                            @endforeach
                                        </select>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTable" id="editable">
                            <thead>
                                <tr>
                                    {{--<th width="15">--}}
                                        {{--<input type="checkbox" class="checkall" name="selectall" />--}}
                                    {{--</th>--}}
                                    <th>序号</th>
                                    <th>广告位置</th>
                                    <th width="300">标题</th>
                                    <th class="center">楼层位置</th>
                                    <th class="center">图片</th>
                                    <th class="center">前台展示</th>
                                    <th class="center">更新时间</th>
                                    <th class="center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if(!empty($list))
                                    @foreach($list as $k =>$v)
                                    <tr class="gradeX">
                                        {{--<th>--}}
                                            {{--<input type="checkbox" class="checkall" name="checkBox[]" value="" />--}}
                                        {{--</th>--}}
                                        <td>{{$v['id']}}</td>
                                        <td>{{$v['advertisement_position']['title']}}</td>
                                        <td>{{$v['title']}}</td>
                                        <td>{{$v['product_categories']['name']}}</td>
                                        <td class="center"><img src="{{$v['image']}}" width="100px" height="50px"></td>
                                        <td class="center" id="audit_text_{{$v['id']}}">
                                            @if($v['audit']==1)
                                                <a href="javascript:void 0;" onclick="audit({{$v['id'].',0'}})">取消展示</a>
                                            @else
                                                <a href="javascript:void 0;" onclick="audit({{$v['id'].',1'}})">展示</a>
                                            @endif
                                        </td>

                                        <td class="center">{{!empty($v['updated_at'])?$v['updated_at']:date('Y-m-d H:i',time()) }}</td>
                                        <td class="center">
                                            <a class="btn btn-xs btn-warning" href="/foradmin/advertisinglist/{{$v['id']}}/edit">编辑</a>
                                            <button class="btn btn-xs btn-danger"
                                                    data-url="{{URL::to('foradmin/advertisinglist/'.$v['id'])}}"
                                                    data-toggle="modal"
                                                    data-target="#delete-modal"
                                            >
                                                删除
                                            </button>
                                        </td>
                                    </tr>
                                    @endforeach
                                @else
                                    <tr class="no-records-found center"><td colspan="9">没有找到匹配的记录</td></tr>
                                @endif
                            </tbody>
                        </table>
                        <div class="row">
                            @include('Admin.common.paginate')
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script src="{{asset('js/plugins/layer/laydate/laydate.js')}}"></script>
    <script src="{{asset('js/plugins/layer/layer.min.js')}}"></script>

    <script>
        //查看
        $('.check_order').click(function(){
            var id=$(this).attr('data-id');
            var url = 'foradmin/advertisinglist/'+id;//前端模板测试
            //var url = '/foradmin/order/' + $(this).data('id');//前端正式
            var title = '广告详情';
            open_page(url, title);//打开新页面
        });

        //展示
        function audit(id,audit){
            var msg = '';
            if (audit==1){
                msg = '取消展示';
            }else{
                msg = '展示';
            }
            layer.confirm('确认修改状态为【'+msg+'】状态？',{
                btn: ['确认', '取消'] //可以无限个按钮
            },function(index) {
                $.ajax({
                    url: '{{Request::url()}}/audit/'+id,
                    type: 'put',
                    dataType: 'json',
                    data: {'audit' : audit},
                    success: function (data) {
                        if (0 == data.code) {
    //                        layer.alert(data.message?data.message:data.data, {
    //                            icon: 1
    //                        }, function () {
                                if(audit==0){
                                    var str="<a href=\"javascript:void 0;\" onclick=\"audit("+id+",0)\">展示</a>";
                                    $("#audit_text_"+id).html(str);
                                }else{
                                    var str="<a href=\"javascript:void 0;\" onclick=\"audit("+id+",1)\">取消展示</a>";
                                    $("#audit_text_"+id).html(str);
                                }
    //                            location.reload();
    //                        });
                        } else {
                            layer.alert(data.message, {
                                icon: 2
                            });
                        }
                    }
                });
                layer.close(index);
            })

        }

    </script>
@endsection

@section("after.js")
    @include('Admin.components.modal.delete',['title'=>'操作提示','content'=>'你确定要删除这个广告位置吗?'])
@endsection